#include "General.h"

General* General::instance = 0;

General::General(void)
{
	//Valores default
	this->resolutionCode = 640;
	this->elementBackgroundColor = new Color("000000255");
	this->lineColor = new Color("255000000");
	this->stageBackgroundColor = new Color("000255000");
	this->elementTexture = NULL;
	this->stageTexture = NULL;

	resolutions = new map<int, Resolution * >();
	(*resolutions)[640] = new Resolution(640,480);
	(*resolutions)[800] = new Resolution(800,600);
	(*resolutions)[1024] = new Resolution(1024,768);
	(*resolutions)[1280] = new Resolution(1280,768);
}

General::~General(void) {
	delete this->elementBackgroundColor;
	delete this->lineColor;
	delete this->stageBackgroundColor;
	
	if(this->elementTexture){
		delete this->elementTexture;
	}

	/*if (this->stageTexture!=NULL){
		delete this->stageTexture;
	}*/

	this->resolutions->clear();
	delete this->resolutions;
	
}

General* General::getInstance(){
	if(!instance){
		instance = new General();
	}
	return instance;
}

int General::getResolutionCode(){
	return this->resolutionCode;
}

void General::setResolutionCode( int resolutionCode ){
	if(resolutionCode != 640 && resolutionCode != 800 && resolutionCode != 1024 && resolutionCode != 1280) {
		throw InvalidResolutionException("El codigo de resolucion es erroneo. Los valores posibles son: 640, 800, 1024 y 1280.");
	}
	this->resolutionCode = resolutionCode;
}

Color * General::getElementBackgroundColor(){
	return this->elementBackgroundColor;
}

void General::setElementBackgroundColor( Color * val ){
	this->elementBackgroundColor = val;
}

Color * General::getLineColor(){
	return this->lineColor;
}

void General::setLineColor( Color * val ){
	this->lineColor = val;
}

Color * General::getStageBackgroundColor(){
	return this->stageBackgroundColor;
}

void General::setStageBackgroundColor( Color * val ){
	this->stageBackgroundColor = val;
}

Texture * General::getElementTexture(){
	return this->elementTexture;
}

void General::setElementTexture( Texture * val ){
	this->elementTexture = val;
}

Texture * General::getStageTexture(){
	return this->stageTexture;
}

void General::setStageTexture( Texture * val ){
	this->stageTexture = val;
}

Resolution * General::getResolution(){
	map<int,Resolution *>::iterator iter =  resolutions->find(this->resolutionCode);
	if(iter != resolutions->end()) {
		return iter->second;
	}else {
		throw InvalidResolutionException("La resolucion no es soportada.");
	}

}

void General::setFramesPerSecond( int fps )
{
	this->framesPerSecond = fps;
}

int General::getFramesPerSecond()
{
	return this->framesPerSecond;
}